package cn.swpu.bose;

import cn.swpu.domin.User;
import cn.swpu.service.DepartmentService;
import cn.swpu.service.RoleService;
import cn.swpu.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import javax.annotation.Resource;
import java.lang.reflect.ParameterizedType;


/**
 * Created by 11616 on 2016/7/20.
 */
public abstract   class BoseAction<T> extends ActionSupport implements ModelDriven<T> {
    //*********ModelDriven的支持****************
    protected  T  model;


    public BoseAction(){
        try{
            //通过反射获取model的真实类型
            ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
            Class<T> clazz = (Class<T>) pt.getActualTypeArguments()[0];
            //通过反射创建model实列
            model = clazz.newInstance();
        }catch (Exception e){
             throw new RuntimeException(e);
        }
    }
    @Override
    public T getModel() {
        return model;
    }
        //**********Service实列的声明
    @Resource
    protected RoleService roleService;
    @Resource
    protected DepartmentService departmentService;
    @Resource
    protected UserService userService;
}
